import xlrd
from xlrd import xldate_as_tuple
import datetime
import time
import os
import xml.dom.minidom as minidom
import xml.etree.ElementTree as ET
from xml.etree.ElementTree import ElementTree, Element

xmldir = r'/home/xiang/cme/faster-rcnn-3quanlian/data/VOCdevkit2007/VOC2007/Annotations'
jpgdir = r'/home/xiang/cme/faster-rcnn-3quanlian/data/VOCdevkit2007/VOC2007/JPEGImages'

def main():
    xmllist = os.listdir(xmldir)
    jpglist = os.listdir(jpgdir)
    for xml in xmllist:
       # tree = ElementTree()
       xmlpath = os.path.join(xmldir, xml)
       # root = tree.parse(xmlpath)
       # object = root.findall('object')
       # if len(object)==0:
       date = xml.split('.')
       jpgname = date[0]+".jpg"
       if jpgname not in jpglist:
         os.remove(xmlpath)

if __name__ == '__main__':
    main()

